package com.artogrid.framework.core.service.impl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateOperations;

import com.artogrid.framework.core.service.BaseDao;

public class BaseDaoImpl<T, PK extends Serializable> implements BaseDao<T, PK> {

	/**
	 * DAO所管理的Entity类型.
	 */
	protected Class<T> entityClass;

	@Autowired
	private HibernateOperations hibernateTemplate;

	@SuppressWarnings("unchecked")
	public BaseDaoImpl (){
		Type genType = getClass().getGenericSuperclass();
		Type[] params = ((ParameterizedType)genType).getActualTypeArguments();
		entityClass = (Class<T>)params[0];
	}
	
	
	@Override
	public Object get(Class<?> entityClass, Serializable id) {
		return null;
	}

	@Override
	public void save(T entity) {
		hibernateTemplate.save(entity);
	}
	
	public List<T> getAll() {
		return hibernateTemplate.loadAll(entityClass);
	}

}
